package com.twu.biblioteca.fortests;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created with IntelliJ IDEA.
 * User: ama
 * Date: 11/10/13
 * Time: 10:31 AM
 */
public class InputObject extends InputStream {
    String input;
    String fullInput[];
    int position = 0;
    int workingOnElementAtThisPosition = 0;

    public InputObject(String input) {

        fullInput = input.split("\n");
        this.input = fullInput[workingOnElementAtThisPosition] + "\n";
    }

    @Override
    public int read() throws IOException {
        byte[] bytes = input.getBytes();
        position++;
        if (position == (input.length() + 1)) {
            workingOnElementAtThisPosition++;
            if (workingOnElementAtThisPosition < fullInput.length) {
                input = fullInput[workingOnElementAtThisPosition] + "\n";

            }
            position = 0;
            return -1;
        } else {
            return bytes[position - 1];
        }
    }
}
